package com.free.show;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;

/**
 * <p>
 * Title: Eclipse Plugin Development
 * </p>
 * <p>
 * Description: Free download
 * </p>
 * <p>
 * mail: ganshm@gmail.com
 * </p>
 */

public class TabFolderExample
{
    public static void main(String[] args)
    {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setText("Tab Folder Example");
        shell.setSize(450, 250);
        
        // 创建分页框
        final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER);
        
        for (int loopIndex = 0; loopIndex < 3; loopIndex++)
        {
            // 创建分页项
            TabItem tabItem = new TabItem(tabFolder, SWT.NULL);
            // 设制分页项的标题
            tabItem.setText("Tab " + loopIndex);
            
            Text text = new Text(tabFolder, SWT.BORDER);
            text.setText("This is page " + loopIndex);
            // 设制Control对象
            tabItem.setControl(text);
        }
        
        // add a control
        TabItem tabItem = new TabItem(tabFolder, SWT.NULL);
        tabItem.setText("Tab " + 3);
        Composite composite = new Composite(tabFolder, SWT.BORDER);
        Text text = new Text(composite, SWT.BORDER);
        text.setText("This is page " + 3);
        text.setBounds(10, 10, 100, 20);
        // 设制Control对象
        tabItem.setControl(composite);
        
        tabFolder.setSize(400, 200);
        
        shell.open();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}
